#include <iostream>
#include <string>
#include <map>
#include <cmath>

using namespace std;

map<string, int> numMap = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

bool isPrime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;
        if (a != "zero" &&  a != "one" && a !="two" && a != "three" && a != "four" && a != "five" && a != "six" && a != "seven" && a != "eight" && a != "nine") {
            cout << "Wrong input" << endl;
        }
        if(b != "zero" &&  b != "one" && b !="two" && b != "three" && b != "four" && b != "five" && b != "six" && b != "seven" && b != "eight" && b != "nine") {
            cout << "Wrong input" << endl;
        }
        if(c != "zero" &&  c != "one" && c !="two" && c != "three" && c != "four" && c != "five" && c != "six" && c != "seven" && c != "eight" && c != "nine") {
            cout << "Wrong input" << endl;
        }
    if (numMap.find(a) == numMap.end() || numMap.find(b) == numMap.end() || numMap.find(c) == numMap.end()) {
        cout << "Wrong input" << endl;
        return 0;
    }

    int num = numMap[a] * 100 + numMap[b] * 10 + numMap[c];
    if (num < 100 || num > 999) {
        cout << "Wrong input" << endl;
        return 0;
        
    }
    int fup = num,maks;
    while (true) {
        if (isPrime(maks)) {
            cout << maks << endl;
            return 0;
        }
        if (isPrime(fup)) {
            cout << fup << endl;
            return 0;
        }
        maks --;
        fup++;
    }

    return 0;
}